9a4f42f222a005e72fa57822efec439a670103d8,Java8-JavaFX/src/sevenguis/flightbooker/FlightBooker.java,FlightBooker,start,#Stage#,21
Before Change
}
};
flightType.valueProperty().addListener(bookEnabledAction);
startDate.textProperty().addListener(bookEnabledAction);
returnDate.textProperty().addListener(bookEnabledAction);
flightType.setValue("one-way flight");
After Change
// For comparison, a callback based approach
returnDate.textProperty().addListener((v, o, n) ->
returnDate.setStyle(isDateString(n) ? "" : "-fx-background-color: lightcoral"));
book.disableProperty().bind(Bindings.createBooleanBinding(() -> {
if (flightType.getValue().equals("one-way flight")) {
return !isDateString(startDate.getText());
} else {
return !isDateString(startDate.getText()) ||
!isDateString(returnDate.getText()) ||
stringToDate(startDate.getText()).compareTo(stringToDate(returnDate.getText())) > 0;
}
}, flightType.valueProperty(), startDate.textProperty(), returnDate.textProperty()));
VBox root = new VBox(10, flightType, startDate, returnDate, book);
root.setPadding(new Insets(10));